from pathlib import Path

from core.book_parser import BookParser


def test_chapter_processing():
    # 空内容测试
    class MockItem:
        def get_content(self):
            return "<html><body><script>alert('test')</script></body></html>"

    parser = BookParser(Path("AliceInWonderland.epub"))
    title, text = parser._process_item(MockItem(), 1)

    # 验证空内容处理
    assert title == "Chapter_1", "应生成默认标题"
    assert text == "", "空内容应返回空字符串"

    # 正常内容测试
    class ValidItem:
        def get_content(self):
            return "<html><body><h1>Real Chapter</h1><p>Content</p></body></html>"

    title, text = parser._process_item(ValidItem(), 2)
    assert title == "Real Chapter", "标题提取失败"
    assert text == "Content", "内容提取失败"

test_chapter_processing()